package com.ywk.base.java8.date;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Calendar;

/**
 * @author zbh
 * @date 2022/9/27 10:00
 */
public class Test {
    public static void main(String[] args) {
        /*
         * 计算两个日期之间的差值：
         *      日期1：2020-01-01 12:30:12
         *      日期2：2020-01-01 13:31:13
         */
        Calendar startCalendar = Calendar.getInstance();
        Calendar endCalendar = Calendar.getInstance();

        // 手动设置时间
        startCalendar.set(2020, Calendar.JANUARY, 1, 12, 30, 12);
        endCalendar.set(2020, Calendar.JANUARY, 1, 13, 31, 11);
        /*startCalendar.set(Calendar.MILLISECOND, 0);
        endCalendar.set(Calendar.MILLISECOND, 0);*/

        long diffMill=endCalendar.getTimeInMillis()- startCalendar.getTimeInMillis();

        long diffMin=(diffMill/1000/60);
        System.out.println("相差： " + diffMin + "（分钟）");

        Calendar cal1 = Calendar.getInstance();
        cal1.set(2021, Calendar.MARCH, 3, 00, 00, 00);// 设置年月日时分秒
        Calendar cal2 = Calendar.getInstance();
        cal2.set(2021, Calendar.MARCH, 3, 00, 00, 00);// 设置年月日时分秒

        System.out.println("小时数："+(cal2.getTime().getTime()-cal1.getTime().getTime())/1000/60/60);

        long avgMin=(cal2.getTime().getTime()-cal1.getTime().getTime())/10;
        /*for (int i = 1; i < 11; i++) {
            Date date = new Date();
            date.setTime(avgMin*i);
            LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            System.out.println(date);
        }*/
        System.out.println(cal1.before(cal2));

        int a=1;
        double b=0.1;
        while (a < 10) {
            while (b < 1){
                System.out.println(a+"*"+b+"="+a*b);
               b+=0.1;
            }
            a+=1;
        }

        String format = LocalDateTime.now().format(
                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
        );
        System.out.println(format);
        System.out.println(LocalDateTime.now().minusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));


        boolean[] isNeed=new boolean[3];
        System.out.println(Arrays.toString(isNeed));
    }

}
